package com.ea.eadp.nexus.test.workflow.pc.parentemail;

import com.ea.eadp.nexus.test.common.TestUtil;
import org.openqa.selenium.WebDriver;
import org.testng.Assert;

import com.ea.eadp.nexus.test.common.SystemProperties;
import com.ea.eadp.nexus.test.pageDefinition.pc.ParentEmailChallengePage.ControlDefinitions;
import com.ea.eadp.nexus.test.workflow.WorkflowElementArgument;

public class ParentEmailChallengePageClickNextWorkflowElement
extends ParentEmailChallengeWorkflowElementBase {
    
    public boolean pass = true;
    
    public ParentEmailChallengePageClickNextWorkflowElement(
        WebDriver driver, WorkflowElementArgument args
    ) {
        super(driver, args);
    }
    
    @Override
    public void doAction() {
        super.doAction();
        page.btn_next.click();
    }
    
    @Override
    public void doVerification() {
        if (pass) {
            assertPass();
        }
        else {
            assertFail();
        }
    }
    
    
    
    
    
    private void assertPass() {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {}
        String url = TestUtil.getCurrentUrl(driver);
        String redirectURI = SystemProperties.instance().getProperty(
            SystemProperties.RedirectUri
            );
        Assert.assertTrue(
            url.contains(redirectURI) && url.contains("code="),
            "Verify login complete failed."
        );
    }
    
    private void assertFail() {
        page.txt_errorMessage =
            driver.findElement(ControlDefinitions.txt_errorMessage);
        Assert.assertTrue(
            page.txt_errorMessage.getText().contains(
                "We have not received your email verification." +
                " Please complete this step before you continue"
            )
        );
    }
    
}
